// pagesProperty/pages/event/task/index.js
var app = getApp(), fetchApi = require("../../../../utils/httpPost.js"), common_Js = require("../../../../component/common.js")
import Dialog from '../../../../component/vant/dialog/dialog';
import Toast from '../../../../component/vant/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isLoading: true,
    recordList: [],
    netWork: true,
    state: 0,
    hasData: false,
    eventType: 0,
    pageIndex: 1,
    pageSize: 10,
    currentTab: 0,
    isShowPop: false,
    dateType: '',
    beginDate: '',
    endDate: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // this.onHttpInit();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.data.pageIndex = 1;
    this.setData({
      isLoading:true,
      recordList:[],
    })
    this.onHttpInit();
  },
  onHttpInit: function () {
    var that = this
    fetchApi.httpPost('/repair/record/pick/list', {
      state: 0,
      pageIndex: that.data.pageIndex,
      pageSize: that.data.pageSize,
    }, function (res) {
      console.log("获取任务列表", res)
      if (res.data.code == 0) {
        var records = res.data.data.records;
        if(records.length > 0){
          that.data.pageIndex += 1;
          for (var index in records) {
            that.data.recordList.splice(that.data.recordList.length, 0, records[index]);
          }
          that.setData({
            hasData: true,
            recordList: that.data.recordList
          })
        }
      }else{
        Toast.fail(res.data.msg)
      }
      that.setData({ netWork: true, isLoading: false, })
      // complete
      wx.hideNavigationBarLoading() //完成停止加载
      wx.stopPullDownRefresh() //停止下拉刷新
    }, function () {
      that.setData({ netWork: false, hasData: false, isLoading: false, })
      // complete
      wx.hideNavigationBarLoading() //完成停止加载
      wx.stopPullDownRefresh() //停止下拉刷新
    })
  },
  goDetail(e){
    var item  =e.currentTarget.dataset.item;
    wx.navigateTo({
      url: '../info/index?id=' + item.id,
    })
  },
  onPullDownRefresh: function () {
    this.data.pageIndex = 1;
    this.setData({
      isLoading:true,
      recordList:[],
    })
    this.onHttpInit();
  },
  /**
   * 页面上拉触底事件的处理函数    加载更多
   */
  onReachBottom: function () {
    this.onHttpInit();
  },
})